<template>
    <view>
        <!-- pages/SetOrder/SetOrder.wxml -->

        <!-- <view class="navigtor" style="padding-top:{{statusBarHeight}}px;height:{{titleBarHeight}}px;line-height:{{titleBarHeight}}px;">
  <navigator class="left iconfont icon-help" url="../help/help"></navigator>
  <view class="title">订单管理</view>
</view> -->
        <block v-if="isLogin">
            <!-- <view class="tabs" style="top:{{statusBarHeight+titleBarHeight}}px"> -->
            <view class="tabs">
                <van-dropdown-menu :active-color="mainColor">
                    <van-dropdown-item :value="storeId" :options="stores" @change="storeDropdown" />
                    <van-dropdown-item :value="value1" :options="option1" @change="OrderStatusDropdown" />
                    <van-dropdown-item :value="value2" :options="option2" @change="orderColumnDropdown" />
                </van-dropdown-menu>
            </view>
        </block>

        <!-- <view class="container" style="padding-top: {{statusBarHeight+titleBarHeight+45}}px;"> -->
        <view class="container" style="padding-top: 45px">
            <block v-if="isLogin">
                <block v-if="orderlist.length > 0">
                    <view class="lists" v-for="(item, index) in orderlist" :key="index">
                        <view class="item">
                            <view class="orderNo icon iconfont icon-quanbudingdan color-primary">{{ item.orderNo }}</view>
                            <block v-if="item.status == 0">
                                <view class="tag blue">未开始</view>
                            </block>
                            <block v-else-if="item.status == 1">
                                <view class="tag yellow">进行中</view>
                            </block>
                            <block v-else-if="item.status == 2">
                                <view class="tag finish">已完成</view>
                            </block>
                            <block v-else-if="item.status == 3">
                                <view class="tag gray">已取消</view>
                            </block>
                            <ul class="info">
                                <li>
                                    <image class="roomImg" :src="item.roomImg"></image>
                                </li>
                                <li class="li">
                                    <view class="title">
                                        {{ item.roomName }}({{
                                            item.roomType === 1 ? '小包' : item.roomType === 2 ? '中包' : item.roomType === 3 ? '大包' : item.roomType === 4 ? '豪包' : '商务包'
                                        }})
                                    </view>
                                    <view>
                                        <span class="name">{{ item.storeName }}</span>
                                    </view>
                                    <!-- <view class="name">{{item.storeName}}</view> -->
                                </li>
                            </ul>
                            <!-- 时间段 -->
                            <view class="timeBox">
                                <view class="time">
                                    <view class="hour">{{ magic.splittime(item.startTime)[0] }}:{{ magic.splittime(item.startTime)[1] }}</view>
                                    <view class="date">{{ magic.splitkongge(item.startTime)[0] }}</view>
                                </view>
                                <view class="total border-primary">{{ item.orderHour }}小时</view>
                                <view class="time">
                                    <view class="hour">{{ magic.splittime(item.endTime)[0] }}:{{ magic.splittime(item.endTime)[1] }}</view>
                                    <view class="date">{{ magic.splitkongge(item.endTime)[0] }}</view>
                                </view>
                            </view>
                            <!-- 底部操作 -->
                            <view class="bottom">
                                <view>
                                    <view class="info">创建时间：{{ item.createTime }}</view>
                                    <view class="info" v-if="item.couponName">
                                        使用卡券：
                                        <label>{{ item.couponName }}</label>
                                    </view>
                                    <view class="info">预订用户：{{ item.nickname }}</view>
                                    <view class="info">
                                        手机号码：{{ item.mobile }}
                                        <text class="copyMobile" @tap="copyText" :data-text="item.mobile">复制</text>
                                    </view>
                                </view>
                                <view>
                                    <view>
                                        支付方式：
                                        <text>{{ item.payType === 1 ? '微信' : item.payType === 2 ? '余额' : item.payType === 3 ? '团购' : '套餐' }}</text>
                                    </view>
                                    <view>
                                        实际支付：
                                        <text class="price">￥{{ item.payPrice }}</text>
                                    </view>
                                    <block v-if="item.status == 3">
                                        <view>
                                            订单退款：
                                            <text class="color-attention">￥{{ item.refundPrice }}</text>
                                        </view>
                                    </block>
                                </view>
                            </view>
                            <view class="btns">
                                <block v-if="item.status == 0 || item.status == 1">
                                    <view class="line1">
                                        <button hover-class="button-click" class="btn bg-warning" @tap.stop.prevent="refundOrder" :data-info="item">退款</button>
                                        <button hover-class="button-click" class="btn cancel" @tap.stop.prevent="cancelOrder" :data-info="item">取消</button>
                                    </view>
                                    <view class="line2">
                                        <button hover-class="button-click" class="btn bg-primary1" @tap.stop.prevent="changeOrderUser" :data-info="item">订单转移</button>
                                        <button hover-class="button-click" class="btn bg-primary1" @tap.stop.prevent="changeOrder" :data-info="item">订单修改</button>
                                    </view>
                                    <view class="line3">
                                        <button hover-class="button-click" class="btn bg-primary" @tap.stop.prevent="callMobile" :data-mobile="item.mobile">拨打电话</button>
                                        <block v-if="item.renewBtn">
                                            <button hover-class="button-click" class="btn bg-primary" @tap.stop.prevent="renewClick" :data-info="item">续费</button>
                                        </block>
                                    </view>
                                </block>
                            </view>
                        </view>
                    </view>
                </block>
                <block v-else>
                    <!-- 无订单和未登录 -->
                    <view class="nodata">暂无订单列表</view>
                </block>
            </block>
            <block v-else>
                <view class="containerlogin">
                    <view class="photo">
                        <view class="img">
                            <image src="/static/logo.png" mode="widthFix" />
                        </view>
                        <view class="name">{{ appName }}</view>
                    </view>
                    <button hover-class="button-click" class="loginBtn bg-primary" @getphonenumber="phone" open-type="getPhoneNumber">一键登录</button>
                </view>
            </block>
        </view>
        <!-- 续单弹窗 -->
        <van-dialog use-slot title="订单续费" :show="renewShow" show-cancel-button :before-close="beforeCloseFunction">
            <view class="dialog">
                <view class="item" style="align-items: center">
                    <label>请选择增加的时间：</label>
                    <van-stepper :value="addTime" step="0.5" min="-8" max="8" disable-input @change="onChange" />
                    时
                </view>
                <view class="item">
                    <label>订单原结束时间：</label>
                    <text>{{ orderInfo.endTime }}</text>
                </view>
                <view class="item">
                    <label>增加后结束时间：</label>
                    <text>{{ newTime }}</text>
                </view>
                <view class="item">
                    <label>订单单价：</label>
                    <text class="color-attention">{{ orderInfo.price }}元</text>
                    /小时
                </view>
                <view class="item">
                    <label>支付总价：</label>
                    <text class="color-attention">{{ totalPay }}</text>
                    元
                </view>
            </view>
        </van-dialog>
        <!-- 订单转移弹窗 -->
        <van-dialog use-slot title="订单转移" :show="changeOrderUserShow" show-cancel-button cancel-button-text="取消" confirm-button-text="确认转移" @confirm="cancelChangeUser">
            <view class="dialog">
                <view class="item">
                    <label>门店名称：</label>
                    <text>{{ orderInfo.storeName }}</text>
                </view>
                <view class="item">
                    <label>当前房间：</label>
                    <text>
                        {{ orderInfo.roomName }}（{{
                            orderInfo.roomType === 1
                                ? '小包'
                                : orderInfo.roomType === 2
                                ? '中包'
                                : orderInfo.roomType === 3
                                ? '大包'
                                : orderInfo.roomType === 4
                                ? '豪包'
                                : '商务包'
                        }}）
                    </text>
                </view>
                <view class="item">
                    <label>开始时间：</label>
                    <text>{{ orderInfo.startTime }}</text>
                </view>
                <view class="item">
                    <label>结束时间：</label>
                    <text>{{ orderInfo.endTime }}</text>
                </view>
                <view class="item">
                    <label>会员手机：</label>
                    <input v-model="mobile" type="text" placeholder="请输入目标手机号" maxlength="11" />
                </view>
            </view>
        </van-dialog>
        <!-- 订单修改弹窗 -->
        <van-dialog use-slot title="订单修改" :show="changeOrderShow" show-cancel-button cancel-button-text="取消" confirm-button-text="确认修改" @confirm="cancelChangeOrder">
            <view class="dialog">
                <view class="item">
                    <label>门店名称：</label>
                    <text>{{ orderInfo.storeName }}</text>
                </view>
                <view class="item">
                    <label>房间名称：</label>
                    <picker mode="selector" @change="bindPickerChange" :value="index" :range="values" :data-ids="key">
                        <view class="picker" style="color: blue">
                            {{ values[index] || '请选择' }}
                        </view>
                    </picker>
                </view>
                <view class="item">
                    <label>原开始时间：</label>
                    <text>{{ orderInfo.startTime }}</text>
                </view>
                <view class="item">
                    <label>原结束时间：</label>
                    <text>{{ orderInfo.endTime }}</text>
                </view>
                <view class="item" style="align-items: center">
                    <label>调整开始时间：</label>
                    <van-stepper :value="changeTime" step="0.5" min="-8" max="8" disable-input @change="onChangeTime" />
                    时
                </view>
                <view class="item">
                    <label>新开始时间：</label>
                    <text>{{ changeStartTime }}</text>
                </view>
                <view class="item">
                    <label>新结束时间：</label>
                    <text>{{ changeEndTime }}</text>
                </view>
            </view>
        </van-dialog>
        <!-- 取消订单弹窗 -->
        <van-dialog use-slot title="取消订单" :show="cancelOrderShow" show-cancel-button cancel-button-text="暂不取消" confirm-button-text="确认取消" @confirm="cancelConfirm">
            <view class="dialog">
                <view class="item">
                    <label>门店名称：</label>
                    <text>{{ orderInfo.storeName }}</text>
                </view>
                <view class="item">
                    <label>当前房间：</label>
                    <text>
                        {{ orderInfo.roomName }}（{{
                            orderInfo.roomType === 1
                                ? '小包'
                                : orderInfo.roomType === 2
                                ? '中包'
                                : orderInfo.roomType === 3
                                ? '大包'
                                : orderInfo.roomType === 4
                                ? '豪包'
                                : '商务包'
                        }}）
                    </text>
                </view>
                <view class="item">
                    <label>开始时间：</label>
                    <text>{{ orderInfo.startTime }}</text>
                </view>
                <view class="item">
                    <label>结束时间：</label>
                    <text>{{ orderInfo.endTime }}</text>
                </view>
                <view class="item">
                    <label>取消提示：</label>
                    <text style="color: red; word-wrap: break-word">取消订单，不会进行退款。是否确认取消订单？</text>
                </view>
            </view>
        </van-dialog>
        <!-- 取消订单成功弹窗 -->
        <van-dialog use-slot title="订单取消成功" :show="cancelOrderSuccess" confirm-button-text="好的" @confirm="cancelSuccessConfirm">
            <view class="dialog">
                <view class="item">
                    <label>已为您成功取消订单</label>
                </view>
                <view class="item">
                    <label>当前位置：</label>
                    <text>
                        {{ orderInfo.roomName }}（{{
                            orderInfo.roomType === 1
                                ? '小包'
                                : orderInfo.roomType === 2
                                ? '中包'
                                : orderInfo.roomType === 3
                                ? '大包'
                                : orderInfo.roomType === 4
                                ? '豪包'
                                : '商务包'
                        }}）
                    </text>
                </view>
                <view class="item">
                    <label>开始时间：</label>
                    <text>{{ orderInfo.startTime }}</text>
                </view>
                <view class="item">
                    <label>结束时间：</label>
                    <text>{{ orderInfo.endTime }}</text>
                </view>
            </view>
        </van-dialog>

        <!-- 退款订单弹窗 -->
        <van-dialog use-slot title="订单退款" :show="refundOrderShow" show-cancel-button cancel-button-text="取消" confirm-button-text="确认退款" @confirm="refundConfirm">
            <view class="dialog">
                <view class="item">
                    <label>门店名称：</label>
                    <text>{{ orderInfo.storeName }}</text>
                </view>
                <view class="item">
                    <label>当前房间：</label>
                    <text>
                        {{ orderInfo.roomName }}（{{
                            orderInfo.roomType === 1
                                ? '小包'
                                : orderInfo.roomType === 2
                                ? '中包'
                                : orderInfo.roomType === 3
                                ? '大包'
                                : orderInfo.roomType === 4
                                ? '豪包'
                                : '商务包'
                        }}）
                    </text>
                </view>
                <view class="item">
                    <label>开始时间：</label>
                    <text>{{ orderInfo.startTime }}</text>
                </view>
                <view class="item">
                    <label>结束时间：</label>
                    <text>{{ orderInfo.endTime }}</text>
                </view>
                <view class="item">
                    <label>退款提示：</label>
                    <text style="color: red; word-wrap: break-word">团购支付的订单不退还团购券.是否确认订单退款？</text>
                </view>
            </view>
        </van-dialog>
        <!-- 退款订单成功弹窗 -->
        <van-dialog use-slot title="订单退款成功" :show="refundOrderSuccess" confirm-button-text="好的" @confirm="refundSuccessConfirm">
            <view class="dialog">
                <view class="item">
                    <label>已为您成功进行订单退款</label>
                </view>
                <view class="item">
                    <label>当前位置：</label>
                    <text>
                        {{ orderInfo.roomName }}（{{
                            orderInfo.roomType === 1
                                ? '小包'
                                : orderInfo.roomType === 2
                                ? '中包'
                                : orderInfo.roomType === 3
                                ? '大包'
                                : orderInfo.roomType === 4
                                ? '豪包'
                                : '商务包'
                        }}）
                    </text>
                </view>
                <view class="item">
                    <label>开始时间：</label>
                    <text>{{ orderInfo.startTime }}</text>
                </view>
                <view class="item">
                    <label>结束时间：</label>
                    <text>{{ orderInfo.endTime }}</text>
                </view>
                <view class="item">
                    <view class="color-attention note">订单的卡券/余额/微信支付已退还，团购券需要用户在团购平台申请退款</view>
                </view>
            </view>
        </van-dialog>
    </view>
</template>
<script module="magic" lang="wxs" src="@/utils/magic.wxs"></script>
<script>
// pages/SetOrder/SetOrder.js
var http = require('../../../utils/http');
var util1 = require('../../../utils/util.js');
var Moment = require('../../../lib/moment.js');
const app = getApp();
export default {
    data() {
        return {
            appName: app.globalData.appName,
            statusBarHeight: '',
            titleBarHeight: '',

            option1: [
                {
                    text: '全部状态',
                    value: -1
                },
                {
                    text: '未开始',
                    value: 0
                },
                {
                    text: '进行中',
                    value: 1
                },
                {
                    text: '已取消',
                    value: 3
                },
                {
                    text: '已完成',
                    value: 2
                }
            ],

            option2: [
                {
                    text: '默认排序',
                    value: '0'
                },
                {
                    text: '下单时间',
                    value: '1'
                },
                {
                    text: '预约时间',
                    value: '2'
                }
            ],

            value1: -1,
            value2: '0',
            pageNo: 1,
            pageSize: 10,
            canLoadMore: true,

            //是否还能加载更多
            renewShow: false,

            //续费弹窗
            cancelOrderShow: false,

            //订单取消弹窗
            refundOrderShow: false,

            //订单退款弹窗
            changeOrderUserShow: false,

            //订单转移弹窗
            changeOrderShow: false,

            //订单修改弹窗
            cancelOrderSucShow: false,

            //取消成功弹窗
            refundOrderSucShow: false,

            //退款成功弹窗
            status: '',

            //订单状态筛选
            orderColumn: '',

            //排序
            orderlist: [],

            //订单列表数组
            isLogin: app.globalData.isLogin,

            orderInfo: {
                endTime: '',
                price: '',
                storeName: '',
                roomName: '',
                roomType: 0,
                startTime: ''
            },

            //选择操作的订单
            addTime: 0,

            //续费时长
            changeTime: 0,

            //修改时长
            newTime: '',

            //增加后的时间
            totalPay: 0,

            //增加后支付价格
            beforeCloseFunction: null,

            changeRoomId: '',

            //修改的房间Id
            changeStartTime: '',

            //修改的开始时间
            changeEndTime: '',

            //修改的结束时间
            // payTypes: [{name:'微信支付',value: 1,checked:true},{name:'钱包余额',value: 2}],
            payType: 2,

            storeId: '',
            stores: [],
            userId: '',
            giftBalance: '',
            mainColor: app.globalData.mainColor,
            mobile: '',
            cancelOrderSuccess: false,
            refundOrderSuccess: false,
            roomId: '',
            array: '',
            values: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        let that = this;
        that.setData({
            userId: options.userId,
            beforeCloseFunction: this.beforeClose(),
            isLogin: app.globalData.isLogin,
            statusBarHeight: uni.getStorageSync('statusBarHeight'),
            titleBarHeight: uni.getStorageSync('titleBarHeight')
        });
        this.getOrderListdata('refresh');
        this.getXiaLaListAdmin();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let that = this;
        that.setData({
            isLogin: app.globalData.isLogin
        });
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
        let that = this;
        that.setData({
            orderlist: [],
            //列表数组
            canLoadMore: true,
            //是否还能加载更多
            pageNo: 1
        });
        that.getOrderListdata('refresh');
        uni.stopPullDownRefresh();
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        let that = this;
        if (that.canLoadMore) {
            that.pageNo++;
            this.getOrderListdata('');
        } else {
            uni.showToast({
                title: '我是有底线的...'
            });
        }
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        //管理员获取门店下拉列表数据
        getXiaLaListAdmin: function (e) {
            var that = this;
            //if (app.globalData.isLogin)
            {
                http.request(
                    '/member/store/getStoreList',
                    '1',
                    'get',
                    {},
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('下拉门店数据===');
                        console.info(info);
                        if (info.code == 0) {
                            let stores = [];
                            info.data.map((it) => {
                                stores.push({
                                    text: it.key,
                                    value: it.value
                                });
                            });
                            stores.unshift({
                                text: '全部门店',
                                value: ''
                            });
                            that.setData({
                                stores: stores,
                                storeId: stores[0].value
                            });
                        } else {
                            uni.showModal({
                                content: '请求服务异常，请稍后重试',
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        //门店下拉菜单发生变化
        storeDropdown(event) {
            //console.log(event)
            this.stores.map((it) => {
                if (it.value == event.detail) {
                    this.setData({
                        storeId: it.value
                    });
                }
            });
            this.getOrderListdata('refresh');
        },

        //城市下拉菜单发生变化
        OrderStatusDropdown(event) {
            let that = this;
            //console.log('选择的值')
            this.option1.map((it) => {
                if (it.value == event.detail) {
                    //console.log(it.value)
                    if (it.value == -1) {
                        that.setData({
                            status: ''
                        });
                    } else {
                        that.setData({
                            status: it.value
                        });
                    }
                    that.getOrderListdata('refresh');
                }
            });
        },

        //
        orderColumnDropdown(event) {
            let that = this;
            //console.log('选择的值')
            this.option2.map((it) => {
                if (it.value == event.detail) {
                    //console.log(it.value)
                    if (it.value == 0) {
                        that.setData({
                            orderColumn: '' //排序
                        });
                    } else if (it.value == 1) {
                        that.setData({
                            orderColumn: 'createTime'
                        });
                    } else if (it.value == 2) {
                        that.setData({
                            orderColumn: 'startTime'
                        });
                    }
                    that.getOrderListdata('refresh');
                }
            });
        },

        openDoor(e) {
            var that = this;
            let aindex = e.currentTarget.dataset.index;
            uni.navigateTo({
                url: '../orderDetail/orderDetail?toPage=true&OrderNo=' + aindex
            });
        },

        // 取消弹窗
        cancelOrder(e) {
            var orderInfo = e.currentTarget.dataset.info;
            this.setData({
                cancelOrderShow: true,
                orderInfo: orderInfo
            });
        },

        // 退款弹窗
        refundOrder(e) {
            var orderInfo = e.currentTarget.dataset.info;
            this.setData({
                refundOrderShow: true,
                orderInfo: orderInfo
            });
        },

        // 修改用户弹窗
        changeOrderUser(e) {
            var orderInfo = e.currentTarget.dataset.info;
            this.setData({
                changeOrderUserShow: true,
                mobile: '',
                orderInfo: orderInfo
            });
        },

        // 修改订单弹窗
        changeOrder(e) {
            var orderInfo = e.currentTarget.dataset.info;
            this.getRoomList(orderInfo);
            this.setData({
                changeTime: '',
                changeRoomId: '',
                changeStartTime: orderInfo.startTime,
                changeEndTime: orderInfo.endTime,
                changeOrderShow: true,
                orderInfo: orderInfo
            });
        },

        // 确认转移
        cancelChangeUser() {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/manager/changeOrderUser',
                    '1',
                    'post',
                    {
                        orderId: that.orderInfo.orderId,
                        mobile: that.mobile
                    },
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('返回111===');
                        console.info(info);
                        if (info.code == 0) {
                            uni.showModal({
                                content: '订单转移成功',
                                showCancel: false
                            });
                            that.getOrderListdata('refresh');
                        } else {
                            uni.showModal({
                                content: info.msg,
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        // 确认修改
        cancelChangeOrder() {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/manager/changeOrder',
                    '1',
                    'post',
                    {
                        orderId: that.orderInfo.orderId,
                        roomId: that.roomId,
                        startTime: that.changeStartTime,
                        endTime: that.changeEndTime
                    },
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('返回111===');
                        console.info(info);
                        if (info.code == 0) {
                            uni.showModal({
                                content: '订单修改成功',
                                showCancel: false
                            });
                            that.getOrderListdata('refresh');
                        } else {
                            uni.showModal({
                                content: info.msg,
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        // 确认取消
        cancelConfirm() {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/manager/cancelOrder/' + that.orderInfo.orderId,
                    '1',
                    'post',
                    {
                        orderId: that.orderInfo.orderId
                    },
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('返回111===');
                        console.info(info);
                        if (info.code == 0) {
                            that.setData({
                                cancelOrderSuccess: true
                            });
                            that.getOrderListdata('refresh');
                        } else {
                            uni.showModal({
                                content: info.msg,
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        // 取消成功关闭弹窗
        cancelSuccessConfirm() {
            this.setData({
                cancelOrderSucShow: false
            });
        },

        // 确认退款
        refundConfirm() {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/manager/refundOrder/' + that.orderInfo.orderId,
                    '1',
                    'post',
                    {
                        orderId: that.orderInfo.orderId
                    },
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('返回111===');
                        console.info(info);
                        if (info.code == 0) {
                            that.setData({
                                refundOrderSuccess: true
                            });
                            that.getOrderListdata('refresh');
                        } else {
                            uni.showModal({
                                content: info.msg,
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        // 退款成功关闭弹窗
        refundSuccessConfirm() {
            this.setData({
                refundOrderSucShow: false
            });
        },

        // 续费弹窗
        renewClick(e) {
            var orderInfo = e.currentTarget.dataset.info;
            var currentTimeStamp = Date.now();
            var specifiedTime = new Date(orderInfo.endTime).getTime();
            // 判断是否已经过去了5分钟（5 * 60 * 1000毫秒）
            var isPastFiveMinutes = currentTimeStamp - specifiedTime > 300000;
            // 判断订单结束时间是否在当前时间的5分钟前
            if (isPastFiveMinutes) {
                uni.showModal({
                    title: '温馨提示',
                    content: '订单已结束超过5分钟，不允许续费！请重新下单！',
                    showCancel: false,
                    confirmText: '确定',
                    success(res) {}
                });
            } else {
                this.setData({
                    renewShow: true,
                    orderInfo: orderInfo
                });
                // this.getgiftBalance()
            }
        },

        // 续费加时间
        onChange: function (event) {
            var that = this;
            var addTime = event.detail;
            var newTime = Moment(that.orderInfo.endTime).add(addTime, 'hours').format('YYYY/MM/DD HH:mm');
            //console.log(`newtime:${newTime}`)
            this.setData({
                addTime: addTime,
                newTime: newTime,
                totalPay: (addTime * that.orderInfo.price).toFixed(2)
            });
        },

        // 修改订单时间
        onChangeTime: function (event) {
            var that = this;
            var changeTime = event.detail;
            var newTime = Moment(that.orderInfo.startTime).add(changeTime, 'hours').format('YYYY/MM/DD HH:mm');
            var newEndTime = Moment(that.orderInfo.endTime).add(changeTime, 'hours').format('YYYY/MM/DD HH:mm');
            //console.log(`newtime:${newTime}`)
            this.setData({
                changeTime: changeTime,
                changeStartTime: newTime,
                changeEndTime: newEndTime
            });
        },

        // 支付方式选择
        // radioChange(e){
        //   this.setData({payType: e.detail.value})
        // },
        // 处理续费
        beforeClose() {
            var that = this;
            // 这里一定要用箭头函数，否则访问不到this
            return (type) => {
                //console.log(type)
                if (type === 'cancel') {
                    // 点击取消
                    // return true
                    that.renewCancel();
                } else {
                    // 点击确定
                    if (that.addTime == 0) {
                        uni.showToast({
                            title: '请选择增加时间!'
                        });
                        return;
                    }
                    that.renewConfirm();
                }
            };
        },

        // 续费
        renewConfirm: function () {
            if (!this.addTime) {
                uni.showToast({
                    title: '请选择增加时间',
                    icon: 'none'
                });
                return false;
            } else {
                var that = this;
                if (app.globalData.isLogin) {
                    http.request(
                        '/member/manager/renewByAdmin',
                        '1',
                        'post',
                        {
                            orderId: that.orderInfo.orderId,
                            // "minutes": that.data.addTime * 60,
                            endTime: that.newTime,
                            payType: that.payType,
                            orderNo: that.orderInfo.orderNo
                        },
                        app.globalData.userDatatoken.accessToken,
                        '',
                        function success(info) {
                            console.info('返回111===');
                            console.info(info);
                            if (info.code == 0) {
                                uni.showToast({
                                    title: '续时成功'
                                });
                                that.getOrderListdata('refresh');
                                that.renewCancel();
                            } else {
                                uni.showModal({
                                    content: info.msg,
                                    showCancel: false
                                });
                            }
                        },
                        function fail(info) {}
                    );
                }
            }
        },

        // 取消续费重置数据
        renewCancel: function () {
            this.setData({
                renewShow: false,
                addTime: '',
                newTime: '',
                totalPay: 0,
                payType: 1
            });
        },

        getOrderListdata: function (e) {
            var that = this;
            let message = '';
            if (app.globalData.isLogin) {
                if (e == 'refresh') {
                    //刷新，page变为1
                    message = '正在加载';
                    that.setData({
                        orderlist: [],
                        //列表数组
                        canLoadMore: true,
                        //是否还能加载更多
                        pageNo: 1
                    });
                }
                http.request(
                    '/member/manager/getOrderPage',
                    '1',
                    'post',
                    {
                        pageNo: that.pageNo,
                        pageSize: that.pageSize,
                        status: that.status,
                        storeId: that.storeId,
                        userId: that.userId,
                        orderColumn: that.orderColumn
                    },
                    app.globalData.userDatatoken.accessToken,
                    message,
                    function success(info) {
                        console.info('订单列表===');
                        if (info.code == 0) {
                            if (e == 'refresh') {
                                that.setData({
                                    orderlist: info.data.list
                                });
                                if (info.data.list.length === 0) {
                                    that.setData({
                                        canLoadMore: false
                                    });
                                }
                            } else {
                                if (info.data != null && info.data.list.length <= info.data.total) {
                                    that.setData({
                                        canLoadMore: false
                                    });
                                }
                                let arr = that.orderlist;
                                let arrs = arr.concat(info.data.list);
                                that.setData({
                                    orderlist: arrs
                                });
                            }
                        } else {
                            uni.showModal({
                                content: '请求服务异常，请稍后重试',
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            } else {
                //console.log('未登录失败！')
            }
        },

        phone: function (e) {
            //console.log("授权用户手机号");
            var that = this;
            if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
                uni.showToast({
                    title: '已取消授权'
                });
            }
            if (e.detail.errMsg == 'getPhoneNumber:ok') {
                //console.log('手机号码授权+++++++');
                //console.log(e.detail);
                //console.log('手机号码授权+++++++');
                uni.login({
                    success: function (res) {
                        //console.log('111++++==');
                        //console.log(res);
                        //console.log('111++++==');
                        if (res.code != null) {
                            http.request(
                                '/member/auth/weixin-mini-app-login',
                                '1',
                                'post',
                                {
                                    phoneCode: e.detail.code,
                                    loginCode: res.code
                                },
                                '',
                                '获取中...',
                                function success(info) {
                                    console.info('返回111===');
                                    console.info(info);
                                    if (info.code == 0) {
                                        if (info.data) {
                                            app.globalData.userDatatoken = info.data;
                                            app.globalData.isLogin = true;
                                            that.setData({
                                                isLogin: true
                                            });
                                            //缓存服务器返回的用户信息
                                            uni.setStorageSync('userDatatoken', info.data);
                                            that.getOrderListdata('refresh');
                                        }
                                    }
                                },
                                function fail(info) {}
                            );
                        } else {
                            //console.log('登录失败！' + res.errMsg)
                        }
                    }
                });
            }
        },

        // 获取赠送余额
        getgiftBalance: function () {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/user/getGiftBalance/' + that.orderInfo.storeId,
                    '1',
                    'get',
                    {
                        storeId: that.orderInfo.storeId
                    },
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('赠送余额===');
                        console.info(info);
                        if (info.code == 0) {
                            that.setData({
                                giftBalance: info.data
                            });
                        }
                    },
                    function fail(info) {}
                );
            } else {
                //console.log('未登录失败！')
            }
        },

        callMobile: function (e) {
            var mobile = e.currentTarget.dataset.mobile;
            uni.makePhoneCall({
                phoneNumber: mobile,
                success: function () {
                    //console.log("拨打电话成功！")
                },
                fail: function () {
                    //console.log("拨打电话失败！")
                }
            });
        },

        copyText: function (e) {
            uni.setClipboardData({
                data: e.currentTarget.dataset.text,
                success: function (res) {
                    uni.getClipboardData({
                        success: function (res) {
                            uni.showToast({
                                title: '复制成功'
                            });
                        }
                    });
                }
            });
        },

        bindPickerChange: function (e) {
            console.log('picker发送选择改变，携带值为', e);
            console.log(this.array, 'this.data.stores');
            this.setData({
                index: e.detail.value,
                roomId: this.array[e.detail.value].roomId
            });
            console.log(this.roomId);
        },

        getRoomList: function (e) {
            var that = this;
            http.request(
                '/member/store/getRoomInfoList/' + e.storeId,
                '1',
                'get',
                {
                    // "storeId": e.storeId
                },
                app.globalData.userDatatoken.accessToken,
                '',
                function success(info) {
                    console.info('房间===');
                    if (info.code == 0) {
                        let stores = [];
                        let statusName = '';
                        info.data.map((it) => {
                            statusName = `(${it.status == 1 ? '空闲' : it.status == 2 ? '待清洁' : it.status == 3 ? '使用中' : it.status == 4 ? '已预约' : '禁用'})`;
                            stores.push({
                                text: it.roomName + statusName,
                                value: it.roomId
                            });
                        });
                        if (e.roomId) {
                            const indexArr = info.data.findIndex((item) => item.roomId === e.roomId);
                            that.setData({
                                index: indexArr,
                                roomId: e.roomId
                            });
                        }
                        that.setData({
                            array: info.data,
                            values: stores.map((item) => item.text)
                        });
                    }
                },
                function fail(info) {}
            );
        }
    }
};
</script>
<style>
@import './SetOrder.css';
</style>
